import { defineStore } from 'pinia'

const initCreationData = {
  id: -1,
  name: '',
  picture: '',
  element: '金',
  series: '开天',
  rank: '凡',
  type: '生灵',
  category: '佛门',
  ability: '',
  consume: '',
  atk: '',
  hp: '',
  isDiy: true,
  transform: {
    minScale: 1,
    scale: 1,
    x: 0,
    y: 0,
    realWidth: 0,
    realHeight: 0,
  },
  param: {
    abilityFontSize: 28,
  },
} as Wx.Card.Diy // 当前创作数据

const useDiyStore = defineStore('diy', {
  state: () => ({
    visible: true, // 是否显示 // TODO
    uidMap: {
      name: -1,
      consume: -1,
      atk: -1,
      hp: -1,
      ability: -1,
    } as Record<string, number>,
    creationData: JSON.parse(JSON.stringify(initCreationData)) as Wx.Card.Diy,
    textSource: -1, // 文本来源
    imageUid: -1, // 图片容器uid
    improtData: false, // 导入标识
    abilityFontSizeUid: -1, // 能力描述字体大小
  }),
  actions: {
    show() {
      this.visible = true
    },
    hidden() {
      this.visible = false
    },
    setCreationData(creationData: Wx.Card.Diy) {
      this.creationData = creationData
    },
    setUidMap(name: string, uid: number) {
      this.uidMap[name] = uid
    },
    setVisible(visible: boolean) {
      this.visible = visible
    },
    reset() {
      this.creationData = JSON.parse(JSON.stringify(initCreationData))
    },
    getReset() {
      return JSON.parse(JSON.stringify(initCreationData))
    },
  },
})

export default useDiyStore
